package com.yanqu.road.server.cmd.variety;

import com.yanqu.road.entity.rank.cross.CrossUserRank;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.variety.VarietyProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.match.CrossMatchMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;

import java.math.BigInteger;

/**
 * @author ：zfr
 * @date ：2021/3/17 18:36
 */
@Cmd(code = CrossProtocol.C_VARIETY_RANK_CHANGE, desc = "排行榜变更")
public class VarietyRankChangeCmd extends CrossCommand {
    private VarietyProto.RankChangeCrossReqMsg msg;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        msg = VarietyProto.RankChangeCrossReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossUserRank crossUserRank = new CrossUserRank();
        crossUserRank.setUserId(packet.getPlayerId());
        crossUserRank.setUserBaseInfo(PlayerBasePb.parseBaseUserInfo(msg.getPlayerBaseData()));
        crossUserRank.setValue(BigInteger.valueOf(msg.getValue()));
        CrossMatchMgr.changeUserRank(msg.getGroupId(), msg.getWeekId(), crossUserRank);
    }

    @Override
    public void sendData() {

    }
}
